home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / UCRASM25.ARJ / STRINSL.ASM < prev    next >
Assembly Source File  |  1991-10-12  |  2KB  |  121 lines

  1. StdGrp        group    stdlib,stddata
  2. stddata        segment    para public 'sldata'
  3. stddata        ends
  4. ;
  5. stdlib        segment    para public 'slcode'
  6.         assume    cs:stdgrp
  7. ;
  8. ;
  9. ; strinsl- Inserts one string within another.
  10. ;
  11. ; inputs:
  12. ;
  13. ;    ES:DI-     Points at destination string, the one into which the source
  14. ;               string will be appended.
  15. ;
  16. ;    CS:RET-    Points at the string to insert.
  17. ;
  18. ;    CX-    Index into source string (ES:DI) to begin insertion.
  19. ;
  20. ;
  21. ; Note: The destination string's (ES:DI) buffer must be sufficiently large
  22. ;    to hold the result of the concatentation of the two strings.
  23. ;
  24.         public    sl_strinsl
  25. ;
  26. rtnadrs        equ    2[bp]
  27. srcseg        equ    (0-2)[bp]
  28. destseg        equ    (0-4)[bp]
  29. insindx        equ    (0-6)[bp]
  30. source        equ    (0-8)[bp]
  31. dest        equ    (0-10)[bp]
  32. ;
  33. sl_strinsl    proc    far
  34.         push    bp
  35.         mov    bp, sp
  36.         push    dx        ;Dummy spot
  37.         push    es
  38.         push    cx
  39.         push    si        ;Dummy spot
  40.         push    di
  41.         pushf
  42.         push    ax
  43.                 push    bx
  44.         push    ds
  45.         push    dx
  46.         push    si
  47. ;
  48.         mov    si, rtnadrs
  49.         mov    source, si
  50.         mov    dx, rtnadrs+2
  51.         mov    srcseg, dx
  52.         cld
  53. ;
  54. ; Compute the length of the string to insert.
  55. ;
  56.         xchg    si, di
  57.         mov    es, dx            ;(srcseg)
  58.         mov    al, 0
  59.         mov    cx, 0ffffh
  60.     repne    scasb
  61.         mov    rtnadrs, di
  62.         neg    cx
  63.         dec    cx
  64.         dec    cx
  65.         mov    bx, cx            ;Save for later.
  66. ;
  67. ; Find the length of the dest string.
  68. ;                 
  69.         xchg    si, di
  70.         mov    es, destseg
  71.         mov    cx, 0ffffh
  72.     repne    scasb
  73. ;
  74. ; Compute the address of the insertion point:
  75. ;
  76.         mov    dx, dest
  77.         add    dx, insindx
  78.         cmp    dx, di            ;See if beyond end of string.
  79.         jb    InsOkay
  80.         lea    dx, (0-1)[di]
  81. InsOkay:
  82. ;
  83. ; Make room for the insertion.
  84. ;
  85.         mov    ds, destseg
  86.         mov    si, di
  87.         add    si, bx
  88.         xchg    si, di
  89.         mov    cx, bx
  90.         std
  91.     rep    movsb
  92. ;
  93. ; Now perform the insertion.
  94. ;
  95.         cld
  96.         mov    si, source
  97.         mov    di, dx
  98.         mov    cx, bx
  99.         mov    ds, srcseg
  100.     rep    movsb
  101. ;
  102. ;                         
  103.         pop    si
  104.         pop    dx
  105.         pop    ds
  106.         pop    bx
  107.         pop    ax
  108.         popf
  109.         pop    di
  110.         pop    cx        ;Dummy
  111.         pop    cx
  112.         pop    es
  113.         pop    bp        ;Dummy
  114.         pop    bp
  115.         ret
  116. sl_strinsl    endp
  117. ;
  118. ;
  119. stdlib        ends
  120.         end
  121.